home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / shootemup / includes / loader.h < prev    next >
Encoding:
Text File  |  2002-04-10  |  4.6 KB  |  240 lines

  1. Const STRVAL=1
  2. Const VERVAL=0
  3.  
  4. Const DEBUG=True
  5.  
  6. Global tag$,out$
  7.  
  8. ;
  9. ; Load Path(s)
  10. ;--
  11.  
  12. ;Include "types.h"
  13. ;Include "math.h"
  14. ;Graphics 640,480
  15. ;loadpath("../path/sqr.arp")
  16. ;loadenermy()
  17.  
  18. Function loadpath(filename$)
  19.  
  20.     memsize=FileSize(filename$)
  21.     memptr=CreateBank(memsize)
  22.     fhr=ReadFile(filename$)
  23.     If fhr=0 Then Return 
  24.     For f=0 To memsize-1
  25.         PokeByte memptr,f,ReadByte(fhr)
  26.     Next
  27.     ; render info
  28.     pathinfo\name$="test"
  29.     pathinfo\memptr=memptr
  30.     pathinfo\xpos=PeekShort(memptr,266)
  31.     pathinfo\ypos=PeekShort(memptr,268)
  32.     pathinfo\dataoffset=PeekShort(memptr,271)
  33.     pathinfo\spacer=PeekShort(memptr,273)
  34.                 
  35.     ; count number of steps for this path
  36.     pathinfo\steps=memsize-pathinfo\dataoffset
  37.     
  38. ;    For x=0 To pathinfo\steps Step 4
  39. ;        xp=PeekShort(memptr,pathinfo\dataoffset+x)
  40. ;        yp=PeekShort(memptr,2+pathinfo\dataoffset+x)
  41. ;        Plot xp,yp
  42. ;    Next
  43. ;    Flip
  44. ;    While Not KeyDown(1) : Wend
  45.     CloseFile(fhr)
  46. End Function
  47.  
  48. ;
  49. ; Read .INI file (ARG!)
  50. ;
  51. ; - Depends on -
  52. ;Include "includes/math.h"
  53. ;Include "includes/types.h"
  54.  
  55. Function loadenermy()
  56.  
  57. ;    Graphics 800,600
  58.  
  59. ;    While Not KeyDown(1) : Wend
  60.  
  61. ;    filename$="../sprites/enermy/aliens.ini"
  62.     filename$="sprites/enermy/aliens.ini"
  63.  
  64.     filesze=FileSize(filename$)
  65.     
  66.     memptr=CreateBank(filesze)
  67.     
  68.     fhr=ReadFile(filename$)
  69.     While Not Eof(fhr)
  70.         PokeByte(memptr,cn,ReadByte(fhr))
  71.         cn=cn+1 
  72.     Wend
  73.     CloseFile(fhr)
  74.     cn=0
  75.     ; nuke the comments :)
  76.     While cn<filesze
  77.         char$=Chr(PeekByte(memptr,cn))
  78.         If char$=";"
  79.             Repeat
  80.                 byte=PeekByte(memptr,cn)
  81.                 If byte<>$0D Then PokeByte(memptr,cn,0)
  82.                 cn=cn+1
  83.             Until byte=$0D
  84.         EndIf
  85.         cn=cn+1
  86.     Wend
  87.     cn=0: char$=""
  88.     ; 0D 0A
  89.     While cn>-1
  90.         cn=findtag(memptr,filesze,cn)
  91.         
  92.         Select Lower(tag$)
  93.             Case "name"
  94.                 findvalue(memptr,filesze,cn,STRVAL)
  95.                 Print "[TAG] - Name - "+out$
  96.                 nmeinfo\name$=out$
  97.  
  98.             Case "file"        
  99.                 findvalue(memptr,filesze,cn,STRVAL)
  100.                 Print "[TAG] - File - "+out$
  101.                 nmeinfo\filename$=out$
  102.             Case "style"
  103.                 findvalue(memptr,filesze,cn,VERVAL)
  104.                 vlo=val("",out$)
  105.                 ;print "[TAG] - Style - "+vlo
  106.                 nmeinfo\style=vlo
  107.                 
  108.             Case "moveable"
  109.                 findvalue(memptr,filesze,cn,VERVAL)
  110.                 vlo=val("",out$)
  111.                 ;print "[TAG] - Moveable - "+vlo
  112.                 nmeinfo\moveable=vlo
  113.  
  114.             Case "canshot"
  115.                 findvalue(memptr,filesze,cn,VERVAL)
  116.                 vlo=val("",out$)
  117.                 ;print "[TAG] - canshot - "+vlo
  118.                 nmeinfo\canshot=vlo
  119.  
  120.             Case "shottype"
  121.                 findvalue(memptr,filesze,cn,VERVAL)
  122.                 vlo=val("",out$)
  123.                 ;print "[TAG] - shottype - "+vlo
  124.                 nmeinfo\shottype=vlo
  125.                 
  126.             Case "energypershot"
  127.                 findvalue(memptr,filesze,cn,VERVAL)
  128.                 vlo=val("",out$)
  129.                 ;print "[TAG] - EnergyPerShot - "+vlo
  130.                 nmeinfo\energypershot=vlo
  131.                 
  132.             Case "damage"
  133.                 findvalue(memptr,filesze,cn,VERVAL)
  134.                 vlo=val("",out$)
  135.                 ;print "[TAG] - Damage - "+vlo
  136.                 nmeinfo\damage=vlo
  137.             Case "frames"
  138.                 findvalue(memptr,filesze,cn,VERVAL)
  139.                 vlo=val("",out$)
  140.                 Print "[TAG] - Frame - "+vlo
  141.                 nmeinfo\frames=vlo
  142.  
  143.             ;-- last tag load image
  144.             If nmeinfo\frames=0
  145.                 nmeinfo\image=LoadImage(nmeinfo\filename$)
  146.                 MaskImage nmeinfo\image,255,0,255
  147.                 DrawImage nmeinfo\image,0,300
  148.             Else
  149.                 nmeinfo\image=LoadAnimImage(nmeinfo\filename$,32,32,0,nmeinfo\frames-1)
  150.                 MaskImage nmeinfo\image,255,0,255
  151.                 DrawImage nmeinfo\image,0,300
  152.             EndIf
  153.  
  154.             ;-- create new                            
  155.                 nmeinfo.nme_inf=New nme_inf
  156.         End Select 
  157.  
  158.         ;char$=Chr(PeekByte(memptr,cn))
  159.         ;byte=PeekByte(memptr,cn)
  160.         
  161.         ;If byte=$0d
  162.         ;    y=y+1 : x=0
  163.         ;EndIf
  164.         
  165.         ;If byte>16
  166.         ;    x=x+1 : If x=60 Then x=0 : y=y+1 : If y=80 Then y=0 : x=0
  167.             ;Text x*12,y*12,char$
  168.         ;EndIf
  169.         ;cn=cn+1
  170.     Wend
  171.     
  172.     FreeBank(memptr)
  173.     
  174.     nmeinfo.nme_inf = First nme_inf
  175.  
  176.     If DEBUG=True Then While Not MouseHit(1) : Wend
  177.  
  178.     
  179. End Function
  180.  
  181. Function findtag(memptr,size,offset)
  182.     cn=offset
  183.     out$=""
  184.     
  185.     Repeat
  186.         tmp$=Chr(PeekByte(memptr,cn))
  187.         If cn=>size-1 
  188.             tag$="" 
  189.             Return -1
  190.         EndIf
  191.         cn=cn+1
  192.     Until tmp$="="
  193.     tmp0=cn-2
  194.     Repeat
  195.         char=PeekByte(memptr,cn)
  196.         If cn<0 
  197.             tag$="" 
  198.             Return -1
  199.         EndIf
  200.         cn=cn-1
  201.     Until char=$0D
  202.     tmp1=cn+3
  203.     
  204.     ;;print tmp0
  205.     ;;print tmp1
  206.  
  207.     For cn=tmp1 To tmp0
  208.         out$=out$+Chr(PeekByte(memptr,cn))
  209.     Next
  210.  
  211.     ;;print out$
  212.     tag$=""
  213.     tag$=out$
  214.     Return tmp0+2
  215.         
  216. End Function
  217.  
  218. Function findvalue(memptr,filesze,cn,mode)
  219.     out$=""
  220.     tmp0=cn
  221.     Repeat
  222.         char=PeekByte(memptr,cn)
  223.         tmp$=Chr$(PeekByte(memptr,cn))
  224. ;        ;print tmp$
  225.         cn=cn+1
  226.         Select char
  227.             Case $20
  228.                 char=$0d
  229.             Case $09
  230.                 char=$0d
  231.         End Select
  232.     Until char=$0D
  233.  
  234.     tmp1=cn-2
  235.     For cn=tmp0+mode To tmp1-mode
  236.         out$=out$+Chr$(PeekByte(memptr,cn))
  237.     Next
  238. ;    ;print out$
  239. ;    ;print tmp1
  240. End Function